﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DDD.Domain
{
    public static class EntityExt
    {
        public static bool ChangeEntity<T>(this T entity, T value) where T : Entity
        {
            //PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance);
            var properties = EntityGetPropertiesExt<T>.properties;

            var flag = false;

            foreach (var p in properties)
            {
                if (p.GetValue(entity) != p.GetValue(value))
                {
                    p.SetValue(entity, p.GetValue(value));
                    flag = true;
                }
            }
            return flag;
        }
    }
}